package com.ruoyi.generator.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.generator.domain.GenChildTables;
import com.ruoyi.generator.service.IGenChildTablesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 子业务对象Controller
 * 
 * @author wudi
 * @date 2023-10-30
 */
@RestController
@RequestMapping("/generator/childTables")
public class GenChildTablesController extends BaseController
{
    @Autowired
    private IGenChildTablesService genChildTablesService;

    /**
     * 查询子业务对象列表
     */
    @PreAuthorize("@ss.hasPermi('generator:childTables:list')")
    @GetMapping("/list")
    public TableDataInfo list(GenChildTables genChildTables)
    {
        startPage();
        List<GenChildTables> list = genChildTablesService.selectGenChildTablesList(genChildTables);
        return getDataTable(list);
    }

    /**
     * 导出子业务对象列表
     */
    @PreAuthorize("@ss.hasPermi('generator:childTables:export')")
    @Log(title = "子业务对象", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GenChildTables genChildTables)
    {
        List<GenChildTables> list = genChildTablesService.selectGenChildTablesList(genChildTables);
        ExcelUtil<GenChildTables> util = new ExcelUtil<GenChildTables>(GenChildTables.class);
        util.exportExcel(response, list, "子业务对象数据");
    }

    /**
     * 获取子业务对象详细信息
     */
    @PreAuthorize("@ss.hasPermi('generator:childTables:query')")
    @GetMapping(value = "/{tableId}")
    public AjaxResult getInfo(@PathVariable("tableId") String tableId)
    {
        return success(genChildTablesService.selectGenChildTablesByTableId(tableId));
    }

    /**
     * 新增子业务对象
     */
    @PreAuthorize("@ss.hasPermi('generator:childTables:add')")
    @Log(title = "子业务对象", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GenChildTables genChildTables)
    {
        return toAjax(genChildTablesService.insertGenChildTables(genChildTables));
    }

    /**
     * 修改子业务对象
     */
    @PreAuthorize("@ss.hasPermi('generator:childTables:edit')")
    @Log(title = "子业务对象", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GenChildTables genChildTables)
    {
        return toAjax(genChildTablesService.updateGenChildTables(genChildTables));
    }

    /**
     * 删除子业务对象
     */
    @PreAuthorize("@ss.hasPermi('generator:childTables:remove')")
    @Log(title = "子业务对象", businessType = BusinessType.DELETE)
	@DeleteMapping("/{tableIds}")
    public AjaxResult remove(@PathVariable String[] tableIds)
    {
        return toAjax(genChildTablesService.deleteGenChildTablesByTableIds(tableIds));
    }
}
